Skip to content

fix: remove redundant type assertion in EditProgramPage#3653

Closed
Adarshkumar0509 wants to merge 3 commits intoOWASP:mainfrom
Adarshkumar0509:fix/redundant-type-assertion-only
Closed

fix: remove redundant type assertion in EditProgramPage#3653
Adarshkumar0509 wants to merge 3 commits intoOWASP:mainfrom
Adarshkumar0509:fix/redundant-type-assertion-only

Conversation

@Adarshkumar0509
Copy link
Contributor

This PR addresses the SonarQube code smell (typescript:S4325) by removing a redundant type assertion in the EditProgramPage component.

Changes

  • Removed the unnecessary (session as ExtendedSession) cast in frontend/src/app/my/mentorship/programs/[programKey]/edit/page.tsx
  • Removed the unused ExtendedSession import
  • The type assertion was redundant because TypeScript already infers the correct type in this context

Testing

  • TypeScript compilation passes without errors
  • ESLint checks pass
  • The change maintains the same functionality for admin access control

Issue

Fixes SonarQube rule typescript:S4325: Redundant casts and non-null assertions should be avoided

This improves code maintainability by removing unnecessary type assertions.

Resolves #3554

Remove the unnecessary (session as ExtendedSession) cast as it does not change the type, addressing SonarQube rule typescript:S4325.

The type assertion was redundant because the compiler already infers the session type correctly in this context.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 29, 2026

Summary by CodeRabbit

  • Style

    • Minor formatting and rendering simplifications on mentorship edit and organizations pages; no changes to user-visible behavior.
  • Chores

    • Removed a duplicate import and simplified an internal check for readability; access control and public interfaces unchanged.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Removed a duplicate ExtendedSession import and reformatted an admin-check arrow in the mentorship program edit page; switched a JSX guard to optional chaining in the organizations listing. No behavioral changes to access control, error handling, or exported signatures. (50 words)

Changes

Cohort / File(s) Summary
Mentorship edit page
frontend/src/app/my/mentorship/programs/[programKey]/edit/page.tsx
Added top-level ExtendedSession import and removed duplicate import; reformatted isAdmin predicate to a single-argument arrow function. No logic or access behavior changed.
Organizations listing
frontend/src/app/organizations/page.tsx
Replaced explicit null/undefined render guard organizations && organizations.map(...) with optional chaining organizations?.map(...). Rendering behavior unchanged when organizations is null/undefined.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested reviewers

  • kasya
  • arkid15r
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The changes to frontend/src/app/organizations/page.tsx (optional chaining refactor) appear unrelated to the stated objective of removing redundant type assertions and are out-of-scope. Remove or justify the optional chaining changes in organizations/page.tsx as they are unrelated to the SonarQube rule typescript:S4325 fix described in issue #3554.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: removing a redundant type assertion in EditProgramPage, which is the primary focus of the PR.
Description check ✅ Passed The description is directly related to the changeset, explaining the removal of redundant type assertions, the import cleanup, and the rationale behind the changes.
Linked Issues check ✅ Passed The PR removes the redundant type assertion from the admin-login comparison in EditProgramPage, directly addressing the SonarQube rule typescript:S4325 outlined in issue #3554.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@frontend/src/app/my/mentorship/programs/`[programKey]/edit/page.tsx:
- Around line 56-58: Add a type-safe cast for session when accessing user.login:
import the ExtendedSession type (import type { ExtendedSession } from
'types/auth') and update the isAdmin check in the isAdmin computation (the
expression using data.getProgram.admins and session) to compare admin.login
against (session as ExtendedSession)?.user?.login so the login property access
is type-safe and matches the pattern used elsewhere.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 29, 2026
@Adarshkumar0509
Copy link
Contributor Author

Changes requested by CodeRabbit have been applied; ready for another look.

@sonarqubecloud
Copy link

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is from a different PR

Comment on lines +56 to +58
const isAdmin = data.getProgram.admins?.some(
(admin: { login: string }) => admin.login === (session as ExtendedSession)?.user?.login
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change indentation here? And I believe the assertion (the issue you needed to fix) is still there 👀

@kasya
Copy link
Collaborator

kasya commented Feb 3, 2026

Closing this in favor of #3628

@kasya kasya closed this Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Sonar issue: Remove redundant type assertion (typescript:S4325)

2 participants

Comments